﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;

namespace ShenLanCMS.Models
{
    public class User
    {
        [Key]
        public Guid UserID { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        [Display(Name = "用户名")]
        [Required(ErrorMessage = "请填写{0}")]
        [StringLength(64)]
        public string UserName { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [Display(Name = "密码")]
        [Required(ErrorMessage = "请填写{0}")]
        [DataType(DataType.Password)]
        [StringLength(32, ErrorMessage = "密码必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        public string Password { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [Display(Name = "邮箱")]        
        [DataType(DataType.EmailAddress, ErrorMessage = "请输入正确的邮箱地址.")]
        [StringLength(64)]
        public string Email { get; set; }

        /// <summary>
        /// 密码保护问题
        /// </summary>
        [Display(Name = "密码保护问题")]
        [StringLength(64)]
        public string PasswordQuestion { get; set; }

        /// <summary>
        /// 密码保护答案
        /// </summary>
        [Display(Name = "密码保护答案")]
        [StringLength(64)]
        public string PasswordAnswer { get; set; }

        /// <summary>
        /// 注册时间
        /// </summary>
        [Display(Name = "注册时间")]
        public DateTime? RegTime { get; set; }

        /// <summary>
        /// 最后活动时间
        /// </summary>
        [Display(Name = "最后活动时间")]
        public DateTime? LastActivityTime { get; set; }

        /// <summary>
        /// 用户详细信息id
        /// </summary>
        [Display(Name = "用户详细信息")]
        public Guid UserInfoID { get; set; }

        /// <summary>
        /// 帐号状态,0为已禁用用户,1为普通用户,2为管理员
        /// </summary>
        [Display(Name = "帐号状态")]
        public int Status { get; set; }
    }

    public class ChangePasswordModel
    {
        [Required(ErrorMessage = "请填写{0}")]
        [DataType(DataType.Password)]
        [Display(Name = "当前密码")]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        public string OldPassword { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "新密码")]
        public string NewPassword { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "确认新密码")]
        [System.Web.Mvc.Compare("NewPassword", ErrorMessage = "新密码和确认密码不匹配。")]
        public string ConfirmPassword { get; set; }
    }

    public class LogOnModel
    {
        [Required(ErrorMessage = "请填写{0}")]
        [Display(Name = "用户名")]
        [StringLength(64)]
        public string UserName { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        public string Password { get; set; }

        [Display(Name = "记住我?")]
        public bool RememberMe { get; set; }
    }

    public class AddUserModel
    {
        [Required]
        [Display(Name = "用户名")]
        [StringLength(64)]
        public string UserName { get; set; }

        [Required]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        public string Password { get; set; }

        [Required]
        [DataType(DataType.Password)]
        [Display(Name = "确认密码")]
        [System.Web.Mvc.Compare("Password", ErrorMessage = "密码和确认密码不匹配。")]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        public string ConfirmPassword { get; set; }

    }

    public class RegisterModel
    {
        [Required(ErrorMessage = "请填写{0}")]
        [Display(Name = "用户名")]
        [StringLength(64)]
        public string UserName { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [StringLength(32, ErrorMessage = "{0}必须至少{2}并且不能大于{1}个字符。", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "密码")]
        public string Password { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [DataType(DataType.Password)]
        [Display(Name = "确认密码")]
        [System.Web.Mvc.Compare("Password", ErrorMessage = "密码和确认密码不匹配。")]
        public string ConfirmPassword { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [Display(Name = "邮箱")]
        [DataType(DataType.EmailAddress)]
        [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "请输入正确的邮箱地址.")]
        [StringLength(64)]
        public string Email { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [Display(Name = "密码保护问题")]
        [StringLength(64)]
        public string PasswordQuestion { get; set; }

        [Required(ErrorMessage = "请填写{0}")]
        [Display(Name = "密码保护答案")]
        [StringLength(64)]
        public string PasswordAnswer { get; set; }
    }
}